package com.clkj.sunhelp.mvp.policyinfo.policykindchoose;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ListView;

import com.clkj.sunhelp.R;
import com.clkj.sunhelp.adapter.grid.GridAdapterForPolicyKind;
import com.clkj.sunhelp.app.CustomApplication;
import com.clkj.sunhelp.bean.PolicyKindItem;
import com.clkj.sunhelp.common.IntentKey;
import com.clkj.sunhelp.mvp.base.BaseActivity;
import com.clkj.sunhelp.mvp.policyinfo.policyinfolist.ActivityPolicyList;
import com.clkj.sunhelp.util.ToastUtil;
import com.clkj.sunhelp.util.schedulers.SchedulerProvider;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/3/26.
 */

public class ActivityPolicyKindChoose extends BaseActivity implements PolicyKindChooseContract.View{


    List<PolicyKindItem> mPolicyKindList = new ArrayList<>();
    GridAdapterForPolicyKind mAdapter;
    private GridView gvPolicyKindChoose;

    private ListView lv;





    PolicyKindChooseContract.Presenter mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_policy_kind_choose);
        initTitleWithRightTvOrIv(null,null,"政策法规",true,null,null);
        initData();
        assignView();
        initView();
        mPresenter = new PolicyKindChoosePresenter(this, SchedulerProvider.getInstance(), CustomApplication.getInstance().getHttpService());
        getPolicyKind();
    }

    @Override
    public void initData() {
       /* mPolicyKindNameList.add("低保户");
        mPolicyKindNameList.add("低保户");
        mPolicyKindNameList.add("低保户");
        mPolicyKindNameList.add("低保户");
        mPolicyKindNameList.add("低保户");
        mPolicyKindNameList.add("低保户");
        mPolicyKindNameList.add("低保户");
        mPolicyKindNameList.add("低保户");
        mPolicyKindNameList.add("低保户");*/
    }

    @Override
    public void assignView() {
        gvPolicyKindChoose = (GridView) findViewById(R.id.gv_policy_kind_choose);
        lv = (ListView) findViewById(R.id.lv);
    }

    @Override
    public void initView() {
        mAdapter = new GridAdapterForPolicyKind(this,mPolicyKindList);
        lv.setAdapter(mAdapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent toPolicyList = new Intent(ActivityPolicyKindChoose.this, ActivityPolicyList.class);
                toPolicyList.putExtra(IntentKey.INTENT_KEY_POLICY_KIND,mPolicyKindList.get(i));
                startActivity(toPolicyList);
            }
        });
    }

    @Override
    public void getPolicyKind() {
        mPresenter.getPolicyKind();
    }

    @Override
    public void onGetPolicyKindSuccess(List<PolicyKindItem> policyKindList) {
        mPolicyKindList.clear();
        mPolicyKindList.addAll(policyKindList);
        mAdapter.notifyDataSetChanged();
    }

    @Override
    public void onGetPolicyKindError(String tip) {
        ToastUtil.showShort(this,tip);
    }

    @Override
    public void setPresenter(PolicyKindChooseContract.Presenter presenter) {

    }

    @Override
    public void showLoading() {
        showProgressDialog(false,null);
    }

    @Override
    public void dismissLoading() {
        dismissProgressDialog();
    }
}
